// 封装优化处理token

// 获取本地存储的数据
export const getItem = (key) => {
  const data = window.localStorage.getItem(key)
  try {
    return JSON.parse(data)
  } catch (error) {
    return data
  }
}

// 存储数据

export const setItem = (key, data) => {
  if (typeof data === 'object') {
    data = JSON.stringify(data)
  }
  window.localStorage.setItem(key, data)
}

// 删除数据
export const clearItem = (key) => {
  window.localStorage.removeItem(key)
}
